﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'usp_UPDMS_FIT_WEIGHT_TRAINING_Get_Training_Id_List')
	BEGIN
		DROP Procedure usp_UPDMS_FIT_WEIGHT_TRAINING_Get_Training_Id_List
	END
GO

SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO
/******************************************************************************
**	Name : usp_UPDMS_FIT_WEIGHT_TRAINING_Get_Training_Id_List
**	Desc : 트레이닝아이디 목록조회 - 트레이닝아이디 수정용
**	Test Exec Query : Exec usp_UPDMS_FIT_WEIGHT_TRAINING_Get_Training_Id_List 'TR00000227','ko'
**	Called by : Fit_Dac_UPDMS_FIT_WEIGHT_TRAINING.cs
**	Program ID : Fit1011m
**	Auth : 송시명
**	Date : 2015-01-12
*******************************************************************************
**	Change History
*******************************************************************************
**	Date:		Author:		Description:
**	--------	--------	---------------------------------------
**	
*******************************************************************************/
CREATE PROC [dbo].[usp_UPDMS_FIT_WEIGHT_TRAINING_Get_Training_Id_List]
@asis_training_id nvarchar(10),
@ls_lang_set nvarchar(2)
AS
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SET NOCOUNT ON

DECLARE @li_training_dt_region int --조회기간(-X월)
SET @li_training_dt_region = CONVERT(int, dbo.ufn_UPDMS_Get_Setting_Value ('FIT_Opt_04')) * (-1);

--설정값이 없으면 -1개월
IF @li_training_dt_region IS NULL OR @li_training_dt_region = ''
BEGIN
  SET @li_training_dt_region = -1
END

SELECT A.Training_Id AS [Value],
       '[' + A.Training_Id + '] ' +
	   '[' + A.Training_Dt + '] ' +
       '[' + CASE @ls_lang_set WHEN 'ko' THEN D.Day_K_Abb_Nm ELSE D.Day_E_Abb_Nm END + '] ' +
       '[' + dbo.ufn_UPDMS_Get_Training_Info_By_Training_Id(A.Training_Id, NULL, 'TRAINING_PART_NM', @ls_lang_set) + ']' AS [Text]
  FROM UPDMS_FIT_WEIGHT_TRAINING A WITH(NOLOCK)
  JOIN UPDMS_MST_DATE D WITH(NOLOCK) ON A.Training_Dt = D.Dt
 WHERE A.Training_Id <> @asis_training_id
   AND A.Training_Dt >= DATEADD(mm, @li_training_dt_region, GETDATE())
 ORDER BY A.Training_Dt DESC

GO